<?php
	$B = new BD();
	class BD {
		private $host;
		private $user;
		private $password;
		private $bd;
		private $link;

		function BD() {
			$this -> host = 'localhost';
			$this -> user = 'root';
			$this -> password = '12345';
			$this -> bd = 'sistemaventasitb';
		}

		function conectar() {
			$this -> link = @mysql_connect($this -> host, $this -> user, $this -> password);
			if (!$this -> link) {
				die("Error conect&aacute;ndose al servidor de base de datos. [host: ".$this -> host." | user: ".$this -> user." | password: ".$this -> password." ]");
			}
			else {
				if (!@mysql_select_db($this -> bd, $this -> link))
					die("Error seleccionando la base de datos. [".$this -> bd."]");
			}
			mysql_query("SET NAMES 'utf8'", $this -> link);
		}

		function desconectar() {
			if ($this -> link)
				mysql_close($this -> link);
		}

		function select($query) {
			$this -> conectar();
			if ($consulta = mysql_query($query)) {
				if (mysql_num_rows($consulta) > 0)
					return true;
			}
			else
				return false;
		}

		function selectXML($query) {
			$this -> conectar();
			$resultado = array();
			if (!$seleccion = mysql_query($query, $this -> link))
				return NULL;
			else {
				if (mysql_num_rows($seleccion) > 0) {
					$i = 0;
					while ($fila = mysql_fetch_row($seleccion)) {
						foreach ($fila as $j => $valor) {
							$campo = mysql_field_name($seleccion, $j);
							$dato[$j] = "<$campo>$valor</$campo>";
							$resultado[$i] = $dato;
						}
						$i++;
					}
				}
				$this -> desconectar();
				return $resultado;
			}
			$this -> desconectar();
		}

		function operacion($query) {
			$this -> conectar();
			if (mysql_query($query))
				return true;
			else
				return false;
		}
	}
?>